jsw.AbstractButton=function(){
	jsw.AbstractButton.superclass.constructor.call(this);
	var model= null;  

this.text                    = ""; // for BeanBox
this.margin                  = null;
this.defaultMargin           = null;
this.defaultIcon             = null;
this.pressedIcon             = null;
this.disabledIcon            = null;
this.selectedIcon            = null;
this.disabledSelectedIcon    = null;
this.rolloverIcon            = null;
this.rolloverSelectedIcon    = null;
this.paintBorder             = true;  
this.paintFocus              = true;
this.rolloverEnabled         = false;   
this.contentAreaFilled         = true; 
this.verticalAlignment       = jsw.AbstractButton.CENTER;
this.horizontalAlignment     = jsw.AbstractButton.CENTER;
this.verticalTextPosition    = jsw.AbstractButton.CENTER;
this.horizontalTextPosition  = jsw.AbstractButton.TRAILING;
this.iconTextGap             = 4;
this.mnemonicIndex           = -1;
this.multiClickThreshhold    = 0;
this.borderPaintedSet        = false;
this.rolloverEnabledSet      = false;
this.iconTextGapSet          = false;
this.contentAreaFilledSet    = false;
this.setLayout = false;
this.defaultCapable = true;
this.handler=null;
this.changeListener = null;
this.actionListener = null;
this.itemListener = null;
this.changeEvent=null;
this.hideActionText = false;
};

jsw.AbstractButton.MODEL_CHANGED_PROPERTY = "model";
jsw.AbstractButton.TEXT_CHANGED_PROPERTY = "text";
jsw.AbstractButton.MNEMONIC_CHANGED_PROPERTY = "mnemonic";
jsw.AbstractButton.MARGIN_CHANGED_PROPERTY = "margin";
jsw.AbstractButton.VERTICAL_ALIGNMENT_CHANGED_PROPERTY = "verticalAlignment";
jsw.AbstractButton.HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY = "horizontalAlignment";
jsw.AbstractButton.VERTICAL_TEXT_POSITION_CHANGED_PROPERTY = "verticalTextPosition";
jsw.AbstractButton.HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY = "horizontalTextPosition";
jsw.AbstractButton.BORDER_PAINTED_CHANGED_PROPERTY = "borderPainted";
jsw.AbstractButton.FOCUS_PAINTED_CHANGED_PROPERTY = "focusPainted";
jsw.AbstractButton.ROLLOVER_ENABLED_CHANGED_PROPERTY = "rolloverEnabled";
jsw.AbstractButton.CONTENT_AREA_FILLED_CHANGED_PROPERTY = "contentAreaFilled";
jsw.AbstractButton.ICON_CHANGED_PROPERTY = "icon";
jsw.AbstractButton.PRESSED_ICON_CHANGED_PROPERTY = "pressedIcon";
jsw.AbstractButton.SELECTED_ICON_CHANGED_PROPERTY = "selectedIcon";
jsw.AbstractButton.ROLLOVER_ICON_CHANGED_PROPERTY = "rolloverIcon";
jsw.AbstractButton.ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY = "rolloverSelectedIcon";
jsw.AbstractButton.DISABLED_ICON_CHANGED_PROPERTY = "disabledIcon";
jsw.AbstractButton.DISABLED_SELECTED_ICON_CHANGED_PROPERTY = "disabledSelectedIcon";
Ext.apply(jsw.AbstractButton,jsw.SwingConstants);
Ext.extend(jsw.AbstractButton,jsw.JComponent,{
	setHideActionText:function(hideActionText) {
        if (hideActionText != this.hideActionText) {
            this.hideActionText = hideActionText;
            if (this.getAction() != null) {
                this.setTextFromAction(this.getAction(), false);
            }
            this._firePropertyChange("hideActionText", !hideActionText,
                               hideActionText);
        }
    },
	getHideActionText:function() {
        return this.hideActionText;
    },
	getText:function() {
        return this.text;
    },
	setText:function(text) {
        var oldValue = this.text;
        this.text = text;
        this._firePropertyChange(jsw.AbstractButton.TEXT_CHANGED_PROPERTY, oldValue, text);
        //this.updateDisplayedMnemonicIndex(text, this.getMnemonic());
        //
        //if (accessibleContext != null) {
        //    accessibleContext.firePropertyChange(
        //        AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
        //        oldValue, text);
        //}
        if (text == null || oldValue == null || !text==oldValue) {
            this.revalidate();
            this.repaint({text:true});
        }
    },
	isSelected:function() {
        return this.model.isSelected();
    },
	setSelected:function(b) {
        var oldValue = this.isSelected();
        this.model.setSelected(b);
    },
	doClick:function(pressTime){
		if(pressTime==null){
			pressTime=68;
		}
		
        var size = this.getSize();
        model.setArmed(true);
        model.setPressed(true);
        this.paintImmediately({click:true});
		//todo:
        //try {
        //    Thread.currentThread().sleep(pressTime);
        //} catch(InterruptedException ie) {
        //}
        this.model.setPressed(false);
        this.model.setArmed(false);
    },
	setMargin:function(Insets m) {
        // Cache the old margin if it comes from the UI
        //if(m instanceof UIResource) {
        //    defaultMargin = m;
        //} else if(margin instanceof UIResource) {
        //    defaultMargin = margin;
        //}
            
        // If the client passes in a null insets, restore the margin
        // from the UI if possible
        //if(m == null && this.defaultMargin != null) {
        //    m = this.defaultMargin;
        //}

        var old = this.margin;
        this.margin = m;
        this._firePropertyChange(jsw.AbstractButton.MARGIN_CHANGED_PROPERTY, old, m);
        if (old == null || !(old.top==m.top && old.left==m.left && old.right==m.right && old.bottom==m.bottom)) {
            this.revalidate();
            this.repaint();
        }
    },
	getMargin:function() {
        return (this.margin == null) ? null : {left:this.margin.left,right:this.margin.right,top:this.margin.top,bottom:this.margin.bottom};
    },
	getIcon:function(){
		//todo
		return null;
	},
	setIcon:function(){
		//todo
	},
	getPressedIcon:function(){},
	setPressedIcon:function(){},
	getSelectedIcon:function(){},
	setSelectedIcon:function(){},
	getVerticalAlignment:function() {
        return this.verticalAlignment;
    },
	setVerticalAlignment:function( alignment) {
        if (alignment == this.verticalAlignment) return;
        var oldValue = this.verticalAlignment;
        this.verticalAlignment = this.checkVerticalKey(alignment, "verticalAlignment");
        this._firePropertyChange(jsw.AbstractButton.VERTICAL_ALIGNMENT_CHANGED_PROPERTY, oldValue, this.verticalAlignment);
		this.repaint();
    },
	getHorizontalAlignment:function() {
        return ths.horizontalAlignment;
    },
	setHorizontalAlignment:function( alignment) {
        if (alignment == this.horizontalAlignment) return;
        int oldValue = this.horizontalAlignment;
        this.horizontalAlignment = this.checkHorizontalKey(alignment,
                                                 "horizontalAlignment");
        this._firePropertyChange(jsw.AbstractButton.HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY,
                           oldValue, this.horizontalAlignment);       
        this.repaint();
    },
	getVerticalTextPosition:function() {
        return this.verticalTextPosition;
    },
	removeNotify:function() {
        jswing.AbstractButton.superclass.removeNotify.apply(this,arguments);
        if(this.isRolloverEnabled()) {
            this.getModel().setRollover(false);
        }
    },
	setActionCommand:function( actionCommand) {
        this.getModel().setActionCommand(actionCommand);
    },
	getActionCommand:function() {
        var ac = this.getModel().getActionCommand();
        if(ac == null) {
            ac = this.getText();
        }
        return ac;
    },
	
	init:function(text, icon) {
        if(text != null) {
            this.setText(text);
        }
        
        if(icon != null) {
            this.setIcon(icon);
        }
        
        // Set the UI
        this.updateUI();

        this.setAlignmentX(jsw.JComponent.LEFT_ALIGNMENT);
        this.setAlignmentY(jsw.JComponent.CENTER_ALIGNMENT);
    }
});

jsw.JButton=function( text,  icon){
	jsw.JButton.superclass.constructor.call(this);
	this.init(text,icon);
};

Ext.extend(jsw.JButton,jsw.AbstractButton,{
		updateUI:function(){
			this.setUI(jsw.UIManager.getUI(this));
		},
});



